﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Srvtools;

public partial class Employees_EmployeeLinkType : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();
            Master.DataSource = WMaster;
            Detail.DataSource = WMaster;

            Bind(WMaster.RealDataSet);
       
            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "";
            master.PageName = "人事类型设置";
            master.PicUrl = "~/image/PageIcon/shu_emp.jpg";
            master.IntiBar();
        }
    }


    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Employees_EmployeeLinkType));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SEmployees.LinkType";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }
    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdFirst" || e.CommandName == "cmdPrevious"
            || e.CommandName == "cmdNext" || e.CommandName == "cmdLast")
        {
            Detail.ExecuteSelect(wfvMaster);
            DataBind();
        }
        else if (e.CommandName == "cmdAdd")
        {
            Detail.ExecuteAdd(wfvMaster);
            DataBind();
        }
        else if (e.CommandName == "cmdDelete")
        {
            Detail.ExecuteSelect(wfvMaster);
            DataBind();

            InitializeComponent();
            Master.DataSource = WMaster;
            Detail.DataSource = WMaster;

            Bind(WMaster.RealDataSet);
        }
        else if (e.CommandName == "cmdApply" && wfvMaster.AllValidateSucess)
        {
            Detail.ExecuteSelect(wfvMaster);
            DataBind();

            InitializeComponent();
            Master.DataSource = WMaster;
            Detail.DataSource = WMaster;

            Bind(WMaster.RealDataSet);
        }
    }

    private void Bind(DataSet DT)
    {
        DDLType.Items.Clear();
        for (int i = 0; i < DT.Tables[0].Rows.Count; i++)
        {
            DDLType.Items.Add(new ListItem(DT.Tables[0].Rows[i]["TypeName"].ToString(), DT.Tables[0].Rows[i]["TypeId"].ToString()));
        }
    }
    protected void wfvMaster_PageIndexChanged(object sender, EventArgs e)
    {
        Detail.ExecuteSelect(wfvMaster);
        DataBind();
    }
    protected void wfvMaster_AfterInsertLocate(object sender, EventArgs e)
    {
        Detail.ExecuteSelect(wfvMaster);
        DataBind();
    }
    protected void wfvMaster_Canceled(object sender, EventArgs e)
    {
        Detail.ExecuteSelect(wfvMaster);
        DataBind();
    }

    protected void Master_Adding(object sender, WebDataSourceAddingEventArgs e)
    {
        //object a = Master.CurrentRow["TypeId"];
        //object b = Master.CurrentRow["TypeName"];
    }
    protected void Master_Updating(object sender, WebDataSourceUpdatingEventArgs e)
    {
        //object a = Master.CurrentRow["TypeId"];
    }

    protected void Search_Click(object sender, EventArgs e)
    {

        InitializeComponent();
        WMaster.SetWhere("TypeId='" + DDLType.SelectedValue + "'");

        Master.DataSource = WMaster;
        Detail.DataSource = WMaster;

        wfvMaster.DataBind();
        wgvDetail.DataBind();

    }
}
